<template>
  <div class="container">
    <!-- 顶部导航 -->
    <van-nav-bar title="首页">
      <template #left>
        <img src="/default.png" alt="茶友网" class="logo"/>
      </template>
      <template #right>
        <van-icon name="search"/>
      </template>
    </van-nav-bar>

    <!-- 功能图标区 -->
    <van-grid :column-num="5">
      <van-grid-item
        v-for="(item, index) in gridList"
        :key="index"
        :icon="item.icon"
        :text="item.text"
        @click="handleGridItemClick(item)"
      />
    </van-grid>

    <!-- 茶叶分类 -->
    <van-grid :column-num="5">
      <van-grid-item
        v-for="(item, index) in teaTypes"
        :key="index"
        :icon="item.icon"
        :text="item.text"
      />
    </van-grid>

    <!-- 价格指数 -->
    <div class="price-index">
      <div class="index-number">
        <span class="green-text">价格指数</span>
        <h1 class="green-text">14984</h1>
      </div>
      <div class="index-trend">
        <div class="trend-item">
          <span>月: ↓ 0.62%</span>
          <span>涨(周)</span>
          <div class="progress-bar"></div>
          <span>239款</span>
        </div>
        <!-- 其他趋势项类似结构 -->
      </div>
    </div>

    <!-- 数据统计 -->
    <div class="data-stat">
      <div class="stat-item">
        <van-icon name="dot" class="red-dot" />
        <span>价格行情</span>
        <span class="stat-number">8250632 条</span>
      </div>
      <!-- 其他统计项类似结构 -->
    </div>

    <!-- 推荐交易 -->
    <div class="recommend-trade">
      <div class="trade-title">
        <van-icon name="arrow-left" />
        <span>推荐交易</span>
        <span @click="moreTrade">更多交易 ></span>
      </div>
      <div class="trade-item" v-for="(item, index) in tradeList" :key="index">
        <img :src="item.img" alt="茶叶" class="trade-img" />
        <div class="trade-info">
          <h3>{{ item.name }}</h3>
          <p>求购价:¥面议</p>
          <p>品牌:{{ item.brand }}</p>
        </div>
        <div class="trade-price">
          <p>行情价:¥{{ item.price }}</p>
          <p>想卖:{{ item.count }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();

const gridList = [
  { icon: '/default.png', text: '产品库',name:'ProductLibrary'},
  { icon: '/default.png', text: '茶行情',name:'' },
  { icon: '/default.png', text: '茶交易' ,name:''},
  { icon: '/default.png', text: '茶品牌' ,name:'TeaBrand'},
  { icon: '/default.png', text: '茶友圈' ,name:''}
];

const teaTypes = [
  { icon: '/default.png', text: '普洱茶' },
  { icon: '/default.png', text: '白茶' },
  { icon: '/default.png', text: '红茶' },
  { icon: '/default.png', text: '黑茶' },
  { icon: '/default.png', text: '绿茶' }
];

const tradeList = [
  {
    img: '/default.png',
    name: '2012年 云梅王圆茶',
    brand: '下关沱茶',
    price: 25,
    count: 2
  },
  {
    img: '/default.png',
    name: '2012年 雪域印象',
    brand: '下关沱茶',
    price: 216,
    count: 2
  }
];

const handleGridItemClick = (item) => {
  router.push({name:item.name})
};
const moreTrade = () => {};
</script>

<style scoped>
.container {
  background: #f5f5f5;
}

.logo {
  height: 24px;
  margin-right: 16px;
}

.banner {
  margin: 16px 0;
}

.banner-img {
  width: 100%;
  height: 120px;
  object-fit: cover;
}

.tea-type {
  margin: 16px 0;
}

.price-index {
  background: white;
  padding: 16px;
  margin: 16px 0;
}

.index-number {
  margin-bottom: 16px;
}

.green-text {
  color: #4cd964;
}

.red-text {
  color: #ff4949;
}

.index-trend .trend-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 8px 0;
}

.progress-bar {
  width: 200px;
  height: 4px;
  background: #eee;
  border-radius: 2px;
}

.data-stat {
  display: flex;
  justify-content: space-around;
  background: white;
  padding: 16px 0;
  margin: 16px 0;
}

.stat-item {
  text-align: center;
}

.stat-number {
  color: #ff4949;
  font-weight: bold;
}

.recommend-trade {
  background: white;
  padding: 16px;
}

.trade-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.trade-item {
  display: flex;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid #eee;
}

.trade-img {
  width: 80px;
  height: 80px;
  margin-right: 16px;
  object-fit: cover;
}

.trade-info {
  flex: 1;
}

.trade-price {
  text-align: right;
}
</style>